home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / gnushogi.lha / gnushogi-1.1 / src / gnushogi.h < prev    next >
C/C++ Source or Header  |  1993-04-23  |  28KB  |  936 lines

  1. /*
  2.  * gnushogi.h - Header file for GNU SHOGI
  3.  *
  4.  * Copyright (c) 1993 Matthias Mutz
  5.  *
  6.  * GNU SHOGI is based on GNU CHESS
  7.  *
  8.  * Copyright (c) 1988,1989,1990 John Stanback
  9.  * Copyright (c) 1992 Free Software Foundation
  10.  *
  11.  * This file is part of GNU SHOGI.
  12.  *
  13.  * GNU Shogi is free software; you can redistribute it and/or modify
  14.  * it under the terms of the GNU General Public License as published by
  15.  * the Free Software Foundation.
  16.  *
  17.  * GNU Shogi is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with GNU Shogi; see the file COPYING.  If not, write to
  24.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  */
  26.  
  27. #if defined THINK_C 
  28.  
  29. /* #define NONDSP */
  30. /* #define DEBUG */
  31. /* #define DEBUG41 */
  32. /* #define DEBUG40 */
  33. /* #define DEBUG_EVAL */
  34. /* OPT */
  35. /* #define XSHOGI */
  36. /* #define BAREBONES */
  37. #define GDX
  38. #define SAVE_PTYPE_DISTDATA
  39. #define SAVE_DISTDATA
  40. #define HARDTIMELIMIT
  41. #define DEBUG9
  42. /* #define NULLMOVE */
  43. #define VERYBUGGY
  44. #define CHECKTRP
  45. #define AG4
  46. #define QUIETBACKGROUND
  47. /* #define HASGETTIMEOFDAY */
  48. #define K32SEGMENTS
  49. struct timeval {
  50.         long    tv_sec;         /* seconds */
  51.         long    tv_usec;        /* and microseconds */
  52. };
  53. extern int gettimeofday(struct timeval *tp, void *tzp);
  54. #define HISTORY
  55. /* #define EXACTHISTORY */
  56. #define CACHE
  57. #define NOSCORESPACE
  58. #define SEMIQUIETBOOKGEN
  59. /* #define NOTTABLE */
  60. /* GENOPT */
  61. #define DROPBONUS
  62. #define FIELDBONUS
  63. #define TESUJIBONUS
  64. /* FILES */
  65. #define LANGFILE "gnushogi.lang"
  66. #define BOOK "gnushogi.book"
  67. #define BINBOOK "gnushogi.book.data"
  68. #define HASHFILE "gnushogi.hash"
  69. #define PATTERNFILE "gnushogi.pattern"
  70. /* #define DEBUG */
  71. #define small_short char
  72. #define small_ushort unsigned char
  73.  
  74. #else
  75.  
  76. #define small_short char
  77. #define small_ushort short
  78.  
  79. #endif
  80.  
  81.  
  82. #if !defined(__STDC__) && !defined(MSDOS)
  83. #define const
  84. #endif
  85.  
  86. #ifndef __GNUC__
  87. #define inline
  88. #endif
  89.  
  90. #include <stdio.h>
  91.  
  92. #define SEEK_SET 0
  93. #define SEEK_END 2
  94. #ifdef DEBUG
  95. void
  96. ShowDBLine (char *, short int, short int,
  97.         short int, short int, short int,
  98.         short unsigned int *);
  99.      extern FILE *debugfd;
  100.      extern short int debuglevel;
  101.  
  102. #endif /* DEBUG */
  103.  
  104. #include <ctype.h>
  105. #include <string.h>
  106. #include <stdlib.h>
  107.  
  108. #ifdef THINK_C
  109. #define RWA_ACC "r+b"
  110. #define WA_ACC "w+b"
  111. #elif defined MSDOS
  112. #include <time.h>
  113. #include <malloc.h>
  114. #define RWA_ACC "r+b"
  115. #define WA_ACC "w+b"
  116. #ifdef timeout
  117. #undef timeout
  118. #endif
  119. #define printz printf
  120. #define scanz scanf
  121. #else
  122. #define RWA_ACC "r+"
  123. #define WA_ACC "w+"
  124. #include <sys/param.h>
  125. #include <sys/types.h>
  126. #include <sys/times.h>
  127. #endif /* MSDOS */
  128. #if defined NONDSP || defined THINK_C
  129. #define printz printf
  130. #define scanz scanf
  131. #else
  132. #include <curses.h>
  133. #define scanz fflush(stdout),scanw
  134. #define printz printw
  135. #endif
  136.  
  137. #ifdef notdef
  138. #if defined(__STDC__) || defined(MSDOS)
  139. /* <stdio.h> */
  140.      extern int fclose (FILE *);
  141. #ifndef __ultrix /* work around bug in c89 compiler --t.mann */
  142.      extern int fscanf (FILE *, const char *, ...);
  143.      extern int fprintf (FILE *, const char *, ...);
  144. #endif /*__ultrix*/
  145.      extern int fflush (FILE *);
  146.  
  147. /* <stdlib.h> */
  148.      extern int abs (int);
  149.      extern int atoi (const char *);
  150.  
  151. /* <time.h> */
  152.      extern long int time (long int *);
  153.  
  154. /* <string.h> */
  155.      extern void *memset (void *, int, size_t);
  156. #endif
  157. #endif
  158.  
  159. #define NO_PIECES 15
  160. #define NO_PTYPE_PIECES 15
  161. #define NO_SQUARES 81
  162. #define NO_COLS 9
  163. #define NO_ROWS 9
  164.  
  165. #if defined HASHFILE || defined CACHE
  166. #define PTBLBDSIZE (NO_SQUARES+NO_PIECES)
  167. #endif
  168.  
  169. /* Piece values and relative values */
  170. #define valueP   70 /* 1 */
  171. #define valuePp 150 /* 2 */
  172. #define valueL  240 /* 3 */
  173. #define valueN  250 /* 4 */
  174. #define valueLp 260 /* 5 */
  175. #define valueNp 270 /* 6 */
  176. #define valueS  340 /* 7 */
  177. #define valueSp 350 /* 8 */
  178. #define valueG  360 /* 9 */
  179. #define valueB  850 /* 10 */
  180. #define valueBp 870 /* 11 */
  181. #define valueR  920 /* 12 */
  182. #define valueRp 970 /* 13 */
  183. #define valueK  1200 /* 14 */
  184. #define SCORE_LIMIT 12000
  185.  
  186. /* masks into upper 16 bits of ataks array */
  187. /* observe order of relative piece values */
  188. #define CNT_MASK 0x000000FF
  189. #define ctlP  0x00200000
  190. #define ctlPp 0x00100000
  191. #define ctlL  0x00080000
  192. #define ctlN  0x00040000
  193. #define ctlLp 0x00020000
  194. #define ctlNp 0x00010000
  195. #define ctlS  0x00008000
  196. #define ctlSp 0x00004000
  197. #define ctlG  0x00002000
  198. #define ctlB  0x00001000
  199. #define ctlBp 0x00000800
  200. #define ctlR  0x00000400
  201. #define ctlRp 0x00000200
  202. #define ctlK  0x00000100
  203.  
  204. /* attack functions */
  205. #define Patak(c, u) (atak[c][u] > ctlP)
  206. #define Anyatak(c, u) (atak[c][u] > 0)
  207.  
  208. /* hashtable flags */
  209. #define truescore 0x0001
  210. #define lowerbound 0x0002
  211. #define upperbound 0x0004
  212. #define kingcastle 0x0008
  213. #define queencastle 0x0010
  214. #define evalflag 0x0020
  215.  
  216. /* king positions */
  217. #define BlackKing PieceList[black][0]
  218. #define WhiteKing PieceList[white][0]
  219. #define OwnKing PieceList[c1][0]
  220. #define EnemyKing PieceList[c2][0]
  221.  
  222. /* constants */
  223.  
  224. #define OPENING_HINT 0x141d /* P7g-7f (20->29) */
  225.  
  226. /* truth values */
  227. #define false 0
  228. #define true 1
  229.  
  230. /* colors */
  231. #define black 0
  232. #define white 1
  233. #define neutral 2
  234.  
  235. /* piece code defines */
  236. #define no_piece 0
  237. #define pawn 1
  238. #define lance 2
  239. #define knight 3
  240. #define silver 4
  241. #define gold 5
  242. #define bishop 6
  243. #define rook 7
  244. #define ppawn 8
  245. #define plance 9
  246. #define pknight 10
  247. #define psilver 11
  248. #define pbishop 12
  249. #define prook 13
  250. #define king 14
  251.  
  252. #define ptype_no_piece 0
  253. #define ptype_pawn 0
  254. #define ptype_lance 1
  255. #define ptype_knight 2
  256. #define ptype_silver 3
  257. #define ptype_gold 4
  258. #define ptype_bishop 5
  259. #define ptype_rook 6
  260. #define ptype_pbishop 7
  261. #define ptype_prook 8
  262. #define ptype_king 9
  263. #define ptype_wpawn 10
  264. #define ptype_wlance 11
  265. #define ptype_wknight 12
  266. #define ptype_wsilver 13
  267. #define ptype_wgold 14
  268.  
  269. /* node flags */
  270. #define pmask        0x000f /*    15 */
  271. #define promote      0x0010 /*    16 */
  272. #define dropmask     0x0020 /*    32 */
  273. #define exact        0x0040 /*    64 */
  274. #define tesuji       0x0080 /*   128 */
  275. #define check        0x0100 /*   256 */
  276. #define capture      0x0200 /*   512 */
  277. #define draw         0x0400 /*  1024 */
  278. #define stupid       0x0800 /*  2048 */
  279. #define questionable 0x1000 /*  4096 */
  280. #define kingattack   0x2000 /*  8192 */
  281. #define book         0x4000 /* 16384 */
  282.  
  283. /* move symbols */
  284. #define pxx (CP[2])
  285. #define qxx (CP[1])
  286. #define rxx (CP[4])
  287. #define cxx (CP[3])
  288. /***************************************************************************/
  289. /***************** Table limits ********************************************/
  290. /*
  291.  * ttblsz must be a power of 2. Setting ttblsz 0 removes the transposition
  292.  * tables.
  293.  */
  294. #if defined NOTTABLE
  295. #define vttblsz 0
  296. #elif defined MSDOS
  297. #define vttblsz (1 << 11)
  298. #elif defined THINK_C
  299. #define vttblsz (1 << 10)
  300. #define huge
  301. #else
  302. #ifdef DEBUG
  303. #define vttblsz (1 << 11)
  304. #else
  305. #define vttblsz (1 << 16)
  306. #endif
  307. /* #define vttblsz (1 << 17) */
  308. #define huge
  309. #endif /* MSDOS */
  310. #define ttblsz vttblsz
  311.  
  312. #if defined THINK_C
  313. #define TREE 2200        /* max number of tree entries */
  314. #else
  315. #define TREE 4000        /* max number of tree entries */
  316. #endif
  317.  
  318. #define MAXDEPTH 20        /* max depth a search can be carried */
  319. #define MINDEPTH 2        /* min search depth =1 (no hint), >1 hint */
  320. #define MAXMOVES 300        /* max number of half moves in a game */
  321. #if defined THINK_C
  322. #define BOOKSIZE 1000
  323. #elif defined MSDOS
  324. #define BOOKSIZE 10000        /* Number of unique position/move combinations allowed */
  325. #else
  326. #define BOOKSIZE 250000        /* Number of unique position/move combinations allowed */
  327. #endif
  328. #define CPSIZE 235        /* size of lang file max */
  329. #ifdef THINK_C
  330. #define ETABLE (2<<10)        /* static eval cache */
  331. #else
  332. #define ETABLE (2<<12)        /* static eval cache */
  333. #endif
  334. /***************** tuning paramaters **********************************************/
  335. #define MINGAMEIN 4
  336. #define MINMOVES 15
  337. #define CHKDEPTH 1        /* always look forward CHKDEPTH half-moves if in check */
  338. #ifdef THINK_C
  339. #define DEPTHBEYOND 9            /* Max to go beyond Sdepth */
  340. #else
  341. #define DEPTHBEYOND 11            /* Max to go beyond Sdepth */
  342. #endif
  343. #define HASHDEPTH 4        /* depth above which to use HashFile */
  344. #define HASHMOVELIMIT 40    /* Use HashFile only for this many moves */
  345. #define PTVALUE 0            /* material value below which pawn threats at 5 & 3 are used */
  346. #define ZDEPTH 3        /* depth beyond which to check ZDELTA for extra time */
  347. #define ZDELTA 10        /* score delta per ply to cause extra time to be given */
  348. #ifdef THINK_C
  349. #define ZNODES (flag.tsume ? 200 : 500)     /* check the time every ZNODES positions */
  350. #else
  351. #define ZNODES (flag.tsume ? 400 : 1000) /* check the time every ZNODES positions */
  352. #endif
  353. #define MAXTCCOUNTX  10        /* max number of time clicks per search to complete ply */
  354. #define MAXTCCOUNTR 4        /* max number of time clicks per search extensions*/
  355. #define SCORESPLIM 8        /* Score space doesn't apply after this stage */
  356. #define SDEPTHLIM Sdepth+1
  357. #define HISTORYLIM 4096        /* Max value of history killer */
  358. #ifdef EXACTHISTORY
  359. #ifdef THINK_C
  360. #define HISTORY_MASK 0x8000     /* mask to MSB of history index */
  361. #define HISTORY_SIZE 0x10000    /* size of history table */
  362. #else
  363. #define HISTORY_MASK (1 << 15)  /* mask to MSB of history index */
  364. #define HISTORY_SIZE (1 << 16)  /* size of history table */
  365. #endif
  366. #else
  367. /* smaller history table, but dangerous because of collisions */
  368. #define HISTORY_MASK 0x3fff     /* mask to significant bits of history index */
  369. #define HISTORY_SIZE (1 << 14)  /* size of history table */
  370. #endif
  371.                                                
  372. #define sizeof_history (sizeof(unsigned short) * (size_t)HISTORY_SIZE)
  373.  
  374. #ifdef EXACTHISTORY
  375. /* Map from.to (8bit.8bit) to from.to (0.7bit.8bit) */
  376. #define hmove(mv) (mv & 0x7fff)
  377. #else
  378. /* Map from.to (8bit.8bit) to from.to (00.7bit.7bit) */
  379. /* Swap bits of ToSquare in case of promotions, hoping that
  380.    no catastrophic collision occur. */
  381. #define hmove(mv) (((mv & 0x7f00) >> 1) | \
  382.                    ((mv & 0x0080) ? ((mv & 0x007f) ^ 0x007f) : (mv & 0x007f)))
  383. #endif
  384.  
  385. /* mask color to 15th bit */
  386. #if defined DEBUG    
  387.      extern char mvstr[4][6];
  388.      extern void movealgbr (short int move, char *s);
  389.      extern void algbr (short int f, short int t, short int flag);
  390. static
  391. unsigned short
  392. hindex(unsigned short c, unsigned short mv)
  393. { unsigned short h;
  394.   h = hmove(mv);
  395. #ifdef EXACTHISTORY
  396.   if ( (h & 0xff) != (mv & 0xff) ||
  397.        ((h>>8) & 0x7f) != ((mv>>8) & 0x7f) ) { 
  398.      algbr ( mv >> 8, mv & 0xff, 0);
  399.      printf("hindex error h=%x mv=%x %s\n",h,mv,mvstr[0]);
  400.   }                
  401. #else
  402.   if ( ((h & 0x7f) ^ ((mv&0x0080)?0x007f:0)) != (mv & 0x7f) ||
  403.        ((h>>7) & 0x7f) != ((mv>>8) & 0x7f) ) { 
  404.      algbr ( mv >> 8, mv & 0xff, 0);
  405.      printf("hindex error h=%x mv=%x %s\n",h,mv,mvstr[0]);
  406.   }                
  407. #endif
  408. #ifdef EXACTHISTORY 
  409.   if ( c ) h |= HISTORY_MASK;
  410. #else               
  411.   /* for white, swap bits, hoping that no catastrophic collision occur. */
  412.   if ( c ) h = (~h) & HISTORY_MASK;
  413. #endif
  414.   if ( h >= HISTORY_SIZE ) {
  415.     printf("hindex(%x,%x)=%x exceeds HISTORY_SIZE=%d\n",
  416.               c, mv, h, HISTORY_SIZE);
  417.     exit(1);
  418.   };
  419.   return (h);
  420. }
  421. #else
  422. #ifdef EXACTHISTORY
  423. #define hindex(c,mv) ((c ? HISTORY_MASK : 0) | hmove(mv))
  424. #else 
  425. /* for white, swap bits, hoping that no catastrophic collision occur. */
  426. #define hindex(c,mv) (c ? ((~hmove(mv)) & HISTORY_MASK) : hmove(mv))
  427. #endif
  428. #endif /* DEBUG */
  429.  
  430. #define EWNDW 10        /* Eval window to force position scoring at depth greater than Sdepth + 2 */
  431. #define WAWNDW 90        /* alpha window when computer black*/
  432. #define WBWNDW 90        /* beta window when computer black*/
  433. #define BAWNDW 90        /* alpha window when computer white*/
  434. #define BBWNDW 90        /* beta window when computer white*/
  435. #define BXWNDW 90        /* window to force position scoring at lower */
  436. #define WXWNDW 90        /* window to force position scoring at lower */
  437.  
  438. #define DITHER 5        /* max amount random can alter a pos value */
  439. #define LBONUS 1        /* points per stage value of L increases */
  440. #define BBONUS 2        /* points per stage value of B increases */
  441. #define RBONUS 2        /* points per stage value of R increases */
  442.                                                            
  443. #define QUESTIONABLE (valueK)   /* malus for questionable moves */
  444. #define STUPID (valueR<<1)      /* malus for stupid moves */
  445.  
  446. #define KINGPOSLIMIT ( -1)    /* King positional scoring limit */
  447. #define KINGSAFETY  32
  448. #define MAXrehash (7)
  449.  
  450. #if defined AG0
  451. #define WHITEAG0
  452. #define BLACKAG0
  453.  
  454. #elif defined AG1
  455. #define WHITEAG1
  456. #define BLACKAG1
  457.  
  458. #elif defined AG2
  459. #define WHITEAG2
  460. #define BLACKAG2
  461.  
  462. #elif defined AG3
  463. #define WHITEAG3
  464. #define BLACKAG3
  465.  
  466. #elif defined AGB
  467. #define WHITEAG2
  468. #define BLACKAG2
  469.  
  470. #elif defined AG4
  471. #define WHITEAG4
  472. #define BLACKAG4
  473. #endif
  474. /************************* parameters for Opening Book *********************************/
  475. #define BOOKFAIL 5        /* if no book move found for BOOKFAIL turns stop using book */
  476. #ifdef THINK_C
  477. #define BOOKMAXPLY 18        /* Max plys to keep in book database */
  478. #else
  479. #define BOOKMAXPLY 28        /* Max plys to keep in book database */
  480. #endif
  481. #define BOOKPOCKET 64
  482. #define BOOKRAND 1000        /* used to select an opening move from a list */
  483. #define BOOKENDPCT 950        /* 5 % chance a BOOKEND will stop the book */
  484. #define DONTUSE -32768        /* flag move as don't use */
  485. /*************************** Book access defines ****************************************/
  486. #define SIDEMASK 0x1
  487. #define LASTMOVE 0x4000        /* means this is the last move of an opening */
  488. #define BADMOVE 0x8000        /* means this is a bad move in this position */
  489. /****************************************************************************************/
  490.      struct hashval
  491.      {
  492.        unsigned long key, bd;
  493.      };
  494.      struct hashentry
  495.      {
  496.        unsigned long hashbd;
  497.        unsigned short mv;
  498.        unsigned char flags, depth;    /* char saves some space */
  499.        unsigned short age;
  500.        short score;
  501. #ifdef HASHTEST
  502.        unsigned char bd[PTBLBDSIZE];
  503. #endif /* HASHTEST */ 
  504.  
  505.      };
  506.  
  507. #if defined HASHFILE || defined CACHE
  508.      struct etable
  509.      { 
  510.     unsigned long ehashbd;
  511.     short int escore[2];
  512.     short int sscore[NO_SQUARES];
  513.     short int score;
  514.     small_short hung[2];
  515. #ifdef CACHETEST
  516.            unsigned char bd[PTBLBDSIZE];
  517. #endif /* CACHETEST */ 
  518.      } ;
  519. #if defined CACHE
  520. typedef struct etable etable_field[ETABLE];
  521. extern etable_field *etab[2];
  522. #endif
  523.  
  524. /*
  525.  * persistent transposition table. The size must be a power of 2. If you
  526.  * change the size, be sure to run gnuchess -c before anything else.
  527.  */
  528. #define frehash 6
  529. #ifdef MSDOS
  530. #define Deffilesz (1 << 11) -1
  531. #elif defined THINK_C
  532. #define Deffilesz (vttblsz - 1)
  533. #else
  534. #define Deffilesz (1 << 17) -1
  535. #endif /* MSDOS */
  536.      struct fileentry
  537.      {
  538.        unsigned char bd[PTBLBDSIZE];
  539.        unsigned char f, t, flags, depth, sh, sl;
  540.      };
  541.  
  542. #endif /* HASHFILE */
  543.  
  544.  
  545.      struct leaf
  546.      {
  547.        small_ushort f, t;
  548.        short score, reply, width;
  549.        unsigned short flags;
  550.      };
  551.      struct GameRec
  552.      {
  553.        unsigned short gmove;    /* this move */
  554.        short score;        /* score after this move */
  555.        short depth;        /* search depth this move */
  556.        long time;               /* search time this move */
  557.        short piece;        /* piece captured */
  558.        short color;        /* color */
  559.        short flags;        /* move flags capture, promote, castle */
  560.        short Game50;        /* flag for repetition */
  561.        long nodes;        /* nodes searched for this move */
  562.        unsigned long hashkey, hashbd;    /* board key before this move */
  563. #ifdef DEBUG40
  564.        int d1;
  565.        int d2;
  566.        int d3;
  567.        int d4;
  568.        int d5;
  569.        int d6;
  570.        int d7;
  571. #endif
  572.      };
  573.      struct TimeControlRec
  574.      {
  575.        short moves[2];
  576.        long clock[2];
  577.      };
  578.  
  579.      struct flags
  580.      {
  581.        short mate;        /* the game is over */
  582.        short post;        /* show principle variation */
  583.        short quit;        /* quit/exit */
  584.        short regularstart;    /* did the game start from standard
  585.                  * initial board ? */
  586.        short reverse;        /* reverse board display */
  587.        short bothsides;        /* computer plays both sides */
  588.        short hash;        /* enable/disable transposition table */
  589.        short force;        /* enter moves */
  590.        short easy;        /* disable thinking on opponents time */
  591.        short beep;        /* enable/disable beep */
  592.        short timeout;        /* time to make a move */
  593.        short musttimeout;    /* time to make a move */
  594.        short back;        /* time to make a move */
  595.        short rcptr;        /* enable/disable recapture heuristics */
  596.        short rv;        /* reverse video */
  597.        short stars;        /* add stars to uxdsp screen */
  598.        short coords;        /* add coords to visual screen */
  599.        short shade;
  600.        short material;        /* draw on lack of material */
  601.        short illegal;        /* illegal position */
  602.        short onemove;        /* timing is onemove */
  603.        short gamein;        /* timing is gamein */
  604.        short tsume;        /* first consider checks */
  605.      };
  606.  
  607. #ifdef DEBUG
  608.      extern FILE *debugfile;
  609.  
  610. #endif /* DEBUG */
  611.  
  612. #ifdef HISTORY
  613.      extern unsigned short *history;
  614. #endif
  615.      extern char *ColorStr[2];
  616.      extern unsigned short int MV[MAXDEPTH];
  617.      extern int MSCORE;
  618.      extern int mycnt1, mycnt2;
  619.      extern short int ahead;
  620.      extern short int xshogi;
  621.      extern struct leaf Tree[], *root,rootnode;
  622.      extern char savefile[], listfile[];
  623.      extern short TrPnt[];
  624.      extern small_short board[], color[]; 
  625.      extern small_short PieceList[2][NO_SQUARES], PawnCnt[2][NO_COLS];
  626.      extern small_short Captured[2][NO_PIECES];
  627.  
  628. #ifdef NOMEMSET
  629. #define ClearCaptured() \
  630.   { short piece, color;\
  631.     for (color = black; color <= white; color++)\
  632.       for (piece = 0; piece < NO_PIECES; piece++)\
  633.         Captured[color][piece] = 0;\
  634.   }
  635. #else
  636. #define ClearCaptured() \
  637.   memset ((char *)Captured, 0,(unsigned long)sizeof(Captured))
  638. #endif /* NOMEMSET */
  639.  
  640.      extern small_short Mvboard[];
  641.  
  642.      extern short svalue[NO_SQUARES];
  643.      extern short pscore[2]; /* eval.c */
  644.      extern int EADD; /* eval.c */
  645.      extern int EGET; /* eval.c */
  646.      extern struct flags flag;
  647.      extern short opponent, computer, INCscore;
  648.      extern short WAwindow, BAwindow, WBwindow, BBwindow;
  649.      extern short dither, player;
  650.      extern short xwndw, contempt;
  651.      extern long ResponseTime, ExtraTime, MaxResponseTime, et, et0, time0, ft;
  652.      extern long reminus, replus;
  653.      extern long GenCnt, NodeCnt, ETnodes, EvalNodes, HashAdd, HashCnt, HashCol, THashCol,
  654.       FHashCnt, FHashAdd;
  655.      extern short HashDepth, HashMoveLimit;
  656.      extern struct GameRec GameList[];
  657.      extern short GameCnt, Game50;
  658.      extern short Sdepth, MaxSearchDepth;
  659.      extern int Book;
  660.      extern struct TimeControlRec TimeControl;
  661.      extern int TCadd;
  662.      extern short TCflag, TCmoves, TCminutes, TCseconds, OperatorTime;
  663.      extern int timecomp[MINGAMEIN], timeopp[MINGAMEIN];
  664.      extern int compptr,oppptr;
  665.      extern short XCmore, XCmoves[], XCminutes[], XCseconds[], XC;
  666.      extern const short otherside[];
  667.      extern const small_short Stboard[];
  668.      extern const small_short Stcolor[];
  669.      extern unsigned short hint;
  670.      extern short int TOflag;
  671.      extern short stage, stage2; 
  672.      extern small_short ChkFlag[], CptrFlag[];
  673.      extern short Pscore[], Tscore[];
  674.      extern /*unsigned*/ short rehash;  /* -1 is used as a flag --tpm */
  675.      extern unsigned int ttblsize;
  676.      extern short mtl[], pmtl[], hung[], emtl[];
  677.      extern small_short Pindex[];
  678.      extern small_short PieceCnt[];
  679.      extern short FROMsquare, TOsquare;
  680.      extern small_short HasPiece[2][NO_PIECES];
  681.      extern const short kingP[];
  682.      extern const small_short sweep[];
  683.      extern unsigned short killr0[], killr1[];
  684.      extern unsigned short killr2[], killr3[];
  685.      extern unsigned short PV, SwagHt, Swag0, Swag1, Swag2, Swag3, Swag4, sidebit;
  686.      extern short mtl[2], pmtl[2], hung[2];
  687.      extern const short value[];
  688.      extern const small_short relative_value[];
  689. #define CatchedValue(side,piece)\
  690.   (10*(((piece==pawn)?3:2)-Captured[side][piece])+value[piece]) 
  691.      extern const long control[];
  692.      extern small_short diagonal(short delta);
  693.      extern const small_short promoted[NO_PIECES],unpromoted[NO_PIECES];
  694.      extern const small_short is_promoted[NO_PIECES];
  695.  
  696. typedef unsigned char next_array[NO_SQUARES][NO_SQUARES];
  697. typedef small_short   distdata_array[NO_SQUARES][NO_SQUARES];
  698.  
  699.      extern next_array *nextpos[NO_PTYPE_PIECES];
  700.      extern next_array *nextdir[NO_PTYPE_PIECES];
  701.  
  702.      extern const small_short ptype[2][NO_PIECES];
  703.  
  704.      extern long filesz,hashmask,hashbase;
  705.      extern FILE *hashfile;
  706.      extern unsigned int starttime;
  707.  
  708. #ifdef SAVE_DISTDATA
  709. #define distance(a,b) \
  710.     ((abs(column (a) - column (b)) > abs (row (a) - row (b)))\
  711.     ? abs(column (a) - column (b)) : abs (row (a) - row (b)))
  712. #else
  713.      extern small_short distdata[NO_SQUARES][NO_SQUARES]; 
  714. #define distance(a,b) (int)distdata[(int)a][(int)b]
  715. #endif
  716.      extern short ptype_distance (short ptyp, short f, short t);
  717.  
  718. #define UNKNOWN 'U'
  719. #define STATIC_ROOK 'S'
  720. #define RANGING_ROOK 'R'
  721.  
  722.      extern char GameType[2];
  723.    
  724. #define CANNOT_REACH -1
  725.  
  726. #ifdef SAVE_PTYPE_DISTDATA
  727. #define piece_distance(side,piece,f,t) \
  728.         (short)ptype_distance(ptype[side][piece],f,t)
  729. #else
  730.      extern distdata_array *ptype_distdata[NO_PTYPE_PIECES];
  731. #define piece_distance(side,piece,f,t) \
  732.         (short)(*ptype_distdata[ptype[side][piece]])[f][t]
  733. #endif                      
  734.  
  735.      extern union U admin;
  736.      extern short unsigned bookmaxply;
  737.      extern int unsigned bookcount;
  738.      extern int unsigned booksize;
  739.      extern unsigned long hashkey, hashbd;
  740.      extern struct hashval hashcode[2][NO_PIECES][NO_SQUARES+(2*NO_PIECES)];
  741.      extern char *CP[];
  742. #ifdef QUIETBACKGROUND
  743.      extern short background;
  744. #endif /* QUIETBACKGROUND */
  745.  
  746. #if ttblsz
  747.      extern struct hashentry huge *ttable[2];
  748. #endif
  749.  
  750. /*
  751.  * hashbd contains a 32 bit "signature" of the board position. hashkey
  752.  * contains a 16 bit code used to address the hash table. When a move is
  753.  * made, XOR'ing the hashcode of moved piece on the from and to squares with
  754.  * the hashbd and hashkey values keeps things current.
  755.  */
  756. #define UpdateHashbd(side, piece, f, t) \
  757. {\
  758.   if ((f) >= 0)\
  759.     {\
  760.       hashbd ^= hashcode[side][piece][f].bd;\
  761.       hashkey ^= hashcode[side][piece][f].key;\
  762.     }\
  763.   if ((t) >= 0)\
  764.     {\
  765.       hashbd ^= hashcode[side][piece][t].bd;\
  766.       hashkey ^= hashcode[side][piece][t].key;\
  767.     }\
  768. }
  769.  
  770.  
  771.  
  772.  
  773.      extern short rpthash[2][256];
  774.      extern char *DRAW;
  775.  
  776.  
  777. #define row(a) ((a) / 9)
  778. #define column(a) ((a) % 9)
  779.  
  780. #define locn(a,b) ((a*9)+b)
  781.  
  782. /* init external functions */
  783.      extern void InitConst (char *lang);
  784.      extern void Initialize_dist (void);
  785.      extern void NewGame (void);
  786.      extern int parse (FILE * fd, short unsigned int *mv, short int side, char *opening);
  787.      extern void GetOpenings (void);
  788.      extern int OpeningBook (unsigned short int *hint, short int side);
  789.      extern void SelectMove (short int side, short int iop);
  790.      extern int
  791.       search (short int side,
  792.            short int ply,
  793.            short int depth,
  794.            short int alpha,
  795.            short int beta,
  796.            short unsigned int *bstline,
  797.            short int *rpt);
  798. #ifdef CACHE
  799.     void
  800.       PutInEETable (short int side,int score);
  801.     int
  802.       CheckEETable (short int side);
  803.     int
  804.       ProbeEETable (short int side, short int *score);
  805. #endif
  806. #if ttblsz
  807.      extern int
  808.       ProbeTTable (short int side,
  809.             short int depth,
  810.             short int ply,
  811.             short int *alpha,
  812.             short int *beta,
  813.             short int *score);
  814.      extern int
  815.       PutInTTable (short int side,
  816.             short int score,
  817.             short int depth,
  818.             short int ply,
  819.             short int alpha,
  820.             short int beta,
  821.             short unsigned int mv);
  822.      extern void ZeroTTable (void);
  823.      extern void ZeroRPT (void);
  824.      extern void Initialize_ttable (void);
  825.      extern unsigned int urand (void);
  826. #ifdef HASHFILE
  827.      extern void gsrand (unsigned int);
  828.      extern int
  829.       ProbeFTable (short int side,
  830.             short int depth,
  831.             short int ply,
  832.             short int *alpha,
  833.             short int *beta,
  834.             short int *score);
  835.      extern void
  836.       PutInFTable (short int side,
  837.             short int score,
  838.             short int depth,
  839.             short int ply,
  840.             short int alpha,
  841.             short int beta,
  842.             short unsigned int f,
  843.             short unsigned int t);
  844.  
  845. #endif /* HASHFILE */
  846. #endif /* ttblsz */
  847.      extern void Initialize_moves (void);
  848.      extern void MoveList (short int side, short int ply);
  849.      extern void CaptureList (short int side, short int ply);
  850.  
  851.      extern void ataks (short int side, long int *a);
  852.  
  853. extern void
  854.       MakeMove (short int side,
  855.          struct leaf * node,
  856.          short int *tempb,
  857.          short int *tempc,
  858.          short int *tempsf,
  859.          short int *tempst,
  860.          short int *INCscore);
  861.      extern void
  862.       UnmakeMove (short int side,
  863.            struct leaf * node,
  864.            short int *tempb,
  865.            short int *tempc,
  866.            short int *tempsf,
  867.            short int *tempst);
  868.      extern void InitializeStats (void);
  869.      extern int
  870.       evaluate (short int side,
  871.          short int ply,
  872.          short int alpha,
  873.          short int beta,
  874.          short int INCscore,
  875.          short int *InChk);
  876.      extern short int ScorePosition (short int side);
  877.      extern void ExaminePosition (void);
  878.      extern void UpdateWeights (void);
  879.      extern void Initialize (void);
  880.      extern void InputCommand (void);
  881.      extern void ExitChess (void);
  882.      extern void ClrScreen (void);
  883.      extern void SetTimeControl (void);
  884.      extern void SelectLevel (char *sx);
  885.      extern void
  886.       UpdateDisplay (short int f,
  887.               short int t,
  888.               short int flag,
  889.               short int iscastle);
  890.      extern void ElapsedTime (short int iop);
  891.      extern void ShowSidetoMove (void);
  892.      extern void SearchStartStuff (short int side);
  893.      extern void ShowDepth (char ch);
  894.      extern void TerminateSearch (int);
  895.      extern void
  896.       ShowResults (short int score,
  897.             short unsigned int *bstline,
  898.             char ch);
  899.      extern void PromptForMove (void);
  900.      extern void SetupBoard (void);
  901.      extern void algbr (short int f, short int t, short int flag);
  902.      extern void OutputMove (void);
  903.      extern void ShowCurrentMove (short int pnt, short int f, short int t);
  904.      extern void ListGame (void);
  905.      extern void ShowMessage (char *s);
  906.      extern void ClrScreen (void);
  907.      extern void gotoXY (short int x, short int y);
  908.      extern void ClrEoln (void);
  909.      extern void DrawPiece (short int sq);
  910.      extern void UpdateClocks (void);
  911.      extern void DoDebug (void);
  912.      extern void DoTable (short table[NO_SQUARES]);
  913.      extern void ShowPostnValues (void);
  914.      extern void ChangeXwindow (void);
  915.      extern void SetContempt (void);
  916.      extern void ChangeHashDepth (void);
  917.      extern void ChangeBetaWindow (void);
  918.      extern void ChangeAlphaWindow (void);
  919.      extern void GiveHint (void);
  920.      extern void ShowPrompt (void);
  921.      extern void EditBoard (void);
  922.      extern void help (void);
  923.      extern void ChangeSearchDepth (void);
  924.      extern void skip (void);
  925.      extern void skipb (void);
  926.      extern void EnPassant (short int xside, short int f, short int t, short int iop);
  927.      extern void ShowNodeCnt (long int NodeCnt);
  928.      extern void ShowLine (short unsigned int *bstline);
  929.      extern int pick (short int p1, short int p2);
  930.      extern int VerifyMove (char *s, short int inp, unsigned short *mv);
  931.      extern void AgeTT();
  932.      extern unsigned short TTage;
  933. #ifdef GDX
  934.      extern struct gdxadmin B;
  935. #endif
  936.